#include "timer.h"

#include "controllers/bs_ws.h"
#include "monitor.h"

using namespace drogon;

void Timer::start_timer1() {
	timer1 = HttpAppFramework::instance().getLoop()->runEvery(5.0, [this] {
		LOG_INFO << "ws_ count: " << ws_.use_count();
		Json::FastWriter writer;
		Json::Value res = get_device_states();
		// std::cout << res.toStyledString() << std::endl;
		if (ws_.get()) {
			ws_->sendMessageToAll("dev", writer.write(res));
		}
	});
}

void Timer::start_timer2() {
}

void Timer::start_timer3() {
}

void Timer::start() {
	ws_ = DrClassMap::getSingleInstance<BsWebSocket>();

	start_timer1();
	start_timer2();
	start_timer3();
}